package com.rhit.rosehack.SQLObjects;

import java.util.ArrayList;

import lombok.Getter;
import lombok.Setter;

public abstract class Creature implements SQLObject {
	// This int is used as the Creature ID, the primary key.
	private @Getter
	@Setter
	int creatureID;

	// This is a name for the creature, doesn't need to be unique.
	private @Getter
	@Setter
	String name;

	// Int representing the level of the creature.
	private @Getter
	@Setter
	int level;

	// HP and MP stats for the creature;
	private @Getter
	@Setter
	int MP, HP;

	// Ints representing the attack, def, and magic stats of the creature
	private @Getter
	@Setter
	int attack, defense, magic;

	// Int representing the type of the creature.
	private @Getter
	@Setter
	int type;

	private ArrayList<Item> inventory;

	// Int representing exp and next level xp
	private int exp, nextxp;

	// Array representing character inventory
	private int[] itemInvent;

	// Int representing carrying capacity
	private int carryCap;

	private @Getter
	@Setter
	int x, y;

	public Creature() {
		inventory = new ArrayList<Item>();
	}

	public int getXP() {
		return this.exp;
	}

	// This checks if a next level is possible to attain, and if so, levels up.
	// Changes based on PC or Mob
	public abstract void checkLevel();

	public int effectiveHP()
	{
		int hp = this.HP;
		for( Item i : inventory )
		{
			hp += i.getHPModifier();
		}
		return hp;
	}

	public int effectiveAttack()
	{
		int a = this.attack;
		for( Item i : inventory )
		{
			a += i.getAttackModifier();
		}
		return a;
	}

	public int effectiveDefense()
	{
		int d = this.defense;
		for( Item i : inventory )
		{
			d += i.getDefenseModifier();
		}
		return d;
	}
	
	public void giveItem(Item i) {
		this.inventory.add(i);
	}

	public Item takeItem(int index) {
		return inventory.remove(index);
	}

	public ArrayList<Item> takeItems() {
		ArrayList<Item> items = new ArrayList<Item>();

		while (inventory.isEmpty() == false)
			items.add(takeItem(0));

		return items;
	}
}
